<?php
/**
 * Author Tim
 * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

class OC_Share_Backend_Offer implements OCP\Share_Backend {

   const FORMAT_OFFER = 0;

   private static $offer;

   public function isValidSource($itemSource, $uidOwner) {
      $object_model = new PCalendarModelObject();
      self::$offer = $object_model->find($itemSource);
      if (self::$offer) {
         return true;
      }
      return false;
   }

   public function generateTarget($itemSource, $shareWith, $exclude = null) {
      if(!self::$offer) {
         $object_model = new PCalendarModelObject();
         self::$offer = $object_model->find($itemSource);
      }
      return self::$offer['summary'];
   }

   public function formatItems($items, $format, $parameters = null) {
      $offer = array();
      if ($format == self::FORMAT_OFFER) {
         $object_model = new PCalendarModelObject();
         foreach ($items as $item) {
            $offer = $object_model->find($item['item_source']);
            $offer['summary'] = $item['item_target'];
            $offer['permissions'] = $item['permissions'];
            $offer[] = $offer;
         }
      }
      return $offer;
   }

}
